<?php

class Quad_Str {
	
	public static function getIpAddressLong() {
		return ip2long(self::getIpAddress());
	}
	
	public static function getIpAddress() {
		if (isset($_SERVER)) {	 	
			if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
				$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
			} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
				$ip = $_SERVER['HTTP_CLIENT_IP'];
			} else {
				$ip = $_SERVER['REMOTE_ADDR'];
			}
		} else {
			if (getenv('HTTP_X_FORWARDED_FOR')) {
				$ip = getenv('HTTP_X_FORWARDED_FOR');
			} elseif (getenv('HTTP_CLIENT_IP')) {
				$ip = getenv('HTTP_CLIENT_IP');
			} else {
				$ip = getenv('REMOTE_ADDR');
			}
		}
		return $ip;    
	}	
	
	public static function isHttps() {
		if ($_SERVER['HTTPS'] == '' || strtolower($_SERVER['HTTPS']) == 'off') {
			// ISAPI on IIS uses "off"
			return false;
		}
		return true;
	}
	
	public static function isLocalhost() {
		return ($_SERVER['SERVER_ADDR'] == '127.0.0.1');
	}
	
	public static function getFullUrlSansProtocol($addPostVars = false) {
		if ($addPostVars) {
			$vars = array_merge($_GET, $_POST);
		}
		else {
			$vars = $_GET;
		}
		return $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . (count($vars) > 0 ? "?" . http_build_query($vars) : '');
	}
	
	public static function getFullUrl($addPostVars = true) {
		return 'http' . (self::isHttps() ? 's' : '') . '://' . self::getFullUrlSansProtocol($addPostVars);
	}
	
}